package com.coocaa.launcher.wallpaper;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.coocaa.x.framework.app.CoocaaApplication;
import com.coocaa.x.framework.utils.LogUtils;
import com.coocaa.x.service.litecontent.data.store.com_coocaa_theme.RP_WallpaperList;

import java.util.List;

public class WallpaperAdapter extends BaseAdapter {
    private Context context = null;
    private List<RP_WallpaperList.WallPaper_Item> wallPaper_items = null;
    private boolean isFirst = true;


    public WallpaperAdapter(Context context) {
        this.context = context;
    }
    @Override
    public int getCount() {
        return wallPaper_items == null ? 0 : wallPaper_items.size();
    }

    @Override
    public Object getItem(int position) {
        return wallPaper_items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        WallpaperItem view = null;
        LogUtils.i("refresh","wallpaper get view");
        if (convertView == null) {
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(CoocaaApplication.Div(384),
                    CoocaaApplication.Div(216));
            view = new WallpaperItem(context);
            view.setLayoutParams(params);
            view.setFocusable(false);
            view.setFocusableInTouchMode(false);
            convertView = view;
            convertView.setTag(view);
        } else {
            view = (WallpaperItem) convertView.getTag();
        }
        view.setData(wallPaper_items.get(position));
        view.setId(position);
        if (isFirst && (position + 1) % 4 == 0)
            convertView.setAlpha(0);
        if (position > 12 || position == wallPaper_items.size() - 1)
            isFirst = false;
        return convertView;
    }

    public void refreshUI(List<RP_WallpaperList.WallPaper_Item> datas) {
        this.wallPaper_items = datas;
        notifyDataSetChanged();
    }

    public void destory() {

    }
}